package main

import (
    "fmt"
)


func solution(n int, m int, s string, c string) int {
    kindsNum := make(map[rune]int)
    kindsUser := make(map[rune]int)

    var buyNumbers int = 0

    for _, i := range s {
        kindsNum[i]++
    }

    for _, j := range c {
        kindsUser[j]++
    }

    for ch := 'a'; ch < 'z'; ch++ {
        if sCount, isOk :=  kindsNum[ch]; isOk {
            if cCount, isOk := kindsUser[ch]; isOk {
                if cCount >= sCount {
                    buyNumbers = buyNumbers + sCount
                } else {
                    buyNumbers = buyNumbers + cCount
                }
            }
        }
    }

    return buyNumbers

}


func main() {
	fmt.Println(solution(3, 4, "abc", "abcd") == 3)
	fmt.Println(solution(4, 2, "abbc", "bb") == 2)
	fmt.Println(solution(5, 4, "bcdea", "abcd") == 4)

}
